<?php
function links_total($lines_total,$lines_limit){
	return $links_total= ceil($lines_total/$lines_limit);
}
function lines_total($table){
	$sql="select count(*) from $table";
	$query=mysql_query($sql);
	$data=mysql_fetch_assoc($query);
	return $data['count(*)'];
}

function lines_total1($table,$ngay,$thang,$nam,$ban){
	if($ngay!=0){
		$sql3="select count(*) from $table where EXTRACT(DAY from date_complete)='$ngay' and EXTRACT(MONTH from date_complete)='$thang' and EXTRACT(YEAR from date_complete)='$nam' and table_id='$ban'";
	}else{
		$sql3="select count(*) from $table where EXTRACT(MONTH from date_complete)='$thang' and EXTRACT(YEAR from date_complete)='$nam' and table_id='$ban'";
	}
	$query3=mysql_query($sql3);
	$data3=mysql_fetch_assoc($query3);
	return $data3['count(*)'];
}

function paging_query($sql,$lines_limit){
	if(!isset($_GET['current'])){
		$current=1;
	}else{
		$current=$_GET['current'];
	}
	$start=($current-1)*$lines_limit;
	$sql="$sql limit $start,$lines_limit";
	return mysql_query($sql);
}

function paging_links1($links_total,$links_limit){
	if(!isset($_GET['current'])){
		$current=1;
	}else{
		$current=$_GET['current'];
	}
	$file="index.php";
	$start=$current-$links_limit;
	if($start<1) $start=1;
	$end=$current+$links_limit;
	if($end>$links_total) $end=$links_total;
	if($start>1){
		echo "<a href='$file?page=sum&current=1'>First</a>";
	}
	for($i=$start;$i<=$end;$i++){
		if($i==$current){
			echo "<span>$i</span>";
		}else{
			echo "<a href='$file?page=sum&current=$i'>$i</a>";
		}
	}
	if($end<$links_total){
		echo "<a href='$file?page=sum&current=$links_total'>Last</a>";
	}
}

function paging_links($links_total,$links_limit){
	if(!isset($_GET['current'])){
		$current=1;
	}else{
		$current=$_GET['current'];
	}
	$file=$_SERVER['PHP_SELF'];
	$start=$current-$links_limit;
	if($start<1) $start=1;
	$end=$current+$links_limit;
	if($end>$links_total) $end=$links_total;
	if($start>1){
		echo "<a href='$file?page=menu_list&current=1'>First</a>";
	}
	for($i=$start;$i<=$end;$i++){
		if($i==$current){
			echo "<span>$i</span>";
		}else{
			echo "<a href='$file?page=menu_list&current=$i'>$i</a>";
		}
	}
	if($end<$links_total){
		echo "<a href='$file?page=menu_list&current=$links_total'>Last</a>";
	}
}

function paging_list($links_total){
	$file=$_SERVER['PHP_SELF'];
	$current=1;
	if(isset($_GET['current'])){
		$current=$_GET['current'];
	}
	echo "<form>";
	echo "<select name='current' onchange='this.form.submit();'>";
	for($i=1;$i<=$links_total;$i++){
		if($i==$current) echo "<option value='$i' selected>$i</option>";
		else echo "<option value='$i'>$i</option>";
	}
	echo "</select>";
	echo "<input type='hidden' name='page' value='$links_total'/>";
	echo "</form>";
}	
?>